<template>
  <div class="project">
    <!-- 项目进度 -->
    <div class="project-part">
      <div class="project-part-title">项目进度</div>
    </div>

    <el-row :gutter="20" align="middle">
      <el-col :span="12">
        <div class="flex items-center h-full">
          <el-select
            v-model="year"
            placeholder="请选择"
            @change="changeYear"
            clearable
            class="w-full"
          >
            <el-option
              v-for="item in yearList"
              :key="item"
              :label="item"
              :value="item"
            />
          </el-select>
        </div>
      </el-col>

      <el-col :span="6">
        <div
          class="field-block"
          style="
            display: flex;
            align-items: center;
            height: 100%;
          "
        >
          <span>本年度计划完成投资(万元)：</span>
          <span>{{ planTotal }}</span>
        </div>
      </el-col>

      <el-col :span="6">
        <div
          class="field-block"
          style="
            display: flex;
            align-items: center;
            height: 100%;
          "
        >
          <span>本年度计划完成固投(万元)：</span>
          <span>{{ fixedTotal }}</span>
        </div>
      </el-col>
    </el-row>

    <el-table
      class="project-table"
      :data="projectList"
      :header-cell-style="{
        background: '#F2F6FB',
        color: ' #6B767D'
      }"
    >
      <el-table-column
        label="年度"
        prop="year"
        width="100"
        show-overflow-tooltip
      />
      <el-table-column
        label="月"
        prop="month"
        width="50"
        show-overflow-tooltip
      />
      <el-table-column
        label="本年度累计完成投资(万元)"
        prop="planTotalInvestment"
        show-overflow-tooltip
      />
      <el-table-column
        label="本年度累计完成固投(万元)"
        prop="fixedTotalInvestment"
        show-overflow-tooltip
      />
      <el-table-column
        label="累计完成投资(万元)"
        prop="totalInvestment"
        show-overflow-tooltip
      />
      <el-table-column
        label="项目建设阶段"
        prop="projectStage"
        show-overflow-tooltip
      />
      <el-table-column
        label="工程形象进度"
        prop="workProcess"
        width="400"
        :cell-class-name="tableCellClass"
      />
      <el-table-column
        label="是否应用统计库"
        prop="joinFlag"
        show-overflow-tooltip
      />
      <el-table-column
        label="入库时间"
        prop="joinTime"
        show-overflow-tooltip
      />
      <el-table-column label="进度图片" prop="imageList">
        <template slot-scope="scope">
          <div
            class="image-wrapper"
            v-if="getImageList(scope.row).length > 0"
          >
            <div
              v-for="(item, index) in getImageList(
                scope.row
              )"
              :key="index"
              class="image-container"
            >
              <el-image
                :src="item.src"
                class="progress-image"
                fit="contain"
                :preview-src-list="
                  getImageList(scope.row).map((i) => i.src)
                "
                :initial-index="index"
              />
            </div>
          </div>
          <span v-else>暂无图片</span>
        </template>
      </el-table-column>
    </el-table>

    <!-- 推进节点 -->
    <div class="project-part">
      <div class="project-part-title">推进节点</div>
    </div>

    <div class="stage-list">
      <div
        v-for="(item, index) in stageList"
        :key="index"
        class="stage-item"
      >
        <div class="stage-header">
          <div class="circle-container">
            <div class="outer-circle active">
              <div class="inner-circle active"></div>
            </div>
          </div>
          <div class="stage-name">{{ item.node }}</div>
        </div>

        <el-row>
          <el-col :span="6">
            <span>办理情况：</span>
            <span>{{ item.finishCondition }}</span>
          </el-col>
          <!-- <el-col :span="6" v-if="item.node === '开工'">
            <span>是否开工：</span>
            <span>{{ item.workFlag }}</span>
          </el-col>
          <el-col :span="6" v-if="item.node === '竣工'">
            <span>是否竣工：</span>
            <span>{{ item.workFlag }}</span>
          </el-col> -->
          <el-col
            :span="6"
            v-if="
              item.finishCondition === '未开始办理' ||
              item.finishCondition === '办理中'
            "
          >
            <span>计划开始时间：</span>
            <span>{{ item.planStartTime }}</span>
          </el-col>
          <el-col
            :span="6"
            v-if="
              item.finishCondition === '未开始办理' ||
              item.finishCondition === '办理中'
            "
          >
            <span>预计完成时间：</span>
            <span>{{ item.planEndTime }}</span>
          </el-col>
          <el-col
            :span="6"
            v-if="
              item.finishCondition === '已办结' ||
              item.node === '开工'
            "
          >
            <span>实际完成时间：</span>
            <span>{{ item.realEndTime }}</span>
          </el-col>
          <el-col
            :span="6"
            v-if="
              item.finishCondition === '未开始办理' ||
              item.finishCondition === '办理中'
            "
          >
            <span>是否存在问题：</span>
            <span>{{ item.problemFlag }}</span>
          </el-col>
        </el-row>

        <el-row>
          <el-col
            :span="6"
            v-if="item.problemFlag === '是'"
          >
            <span>问题描述：</span>
            <span>{{ item.problemContent }}</span>
          </el-col>
          <el-col
            :span="6"
            v-if="item.problemFlag === '是'"
          >
            <span>解决措施：</span>
            <span>{{ item.sloveMeasure }}</span>
          </el-col>

          <!-- <el-col :span="6">
            <span>是否需要协调处理：</span>
            <span>{{ item.workFlag }}</span>
          </el-col> -->
        </el-row>
      </div>
    </div>
  </div>
</template>

<script>
import { STATIC_FILE_URL } from '@/api/config.js'

export default {
  props: {
    nodeList: Array,
    processList: Array,
    planTotal: Number,
    fixedTotal: Number
  },
  data() {
    return {
      year: '',
      projectList: [],
      stageList: [],
      yearList: [],
      allProgressList: []
    }
  },
  watch: {
    processList(val) {
      this.yearList = new Set(val.map((item) => item.year))
      this.allProgressList = val
      this.projectList = JSON.parse(JSON.stringify(val))
    },
    nodeList(val) {
      this.stageList = val
    }
  },
  methods: {
    changeYear() {
      this.year
        ? (this.projectList = this.allProgressList.filter(
            (i) => i.year === this.year
          ))
        : (this.projectList = this.allProgressList)
    },
    tableCellClass() {
      return 'word-wrap'
    },

    // 获取图片列表，处理 resourceFileInfos 数据
    getImageList(item) {
      if (
        !item.resourceFileInfos ||
        !Array.isArray(item.resourceFileInfos)
      ) {
        return []
      }

      return item.resourceFileInfos.map((fileInfo) => ({
        src: `${STATIC_FILE_URL}${fileInfo.filePath}`
      }))
    }
  }
}
</script>

<style lang="scss" scoped>
@import '~@/assets/css/form.scss';
.project {
  padding: 10px 10px 0 10px;

  &-table {
    margin: 20px 0;
  }
}

:v-deep(.el-select .el-input__suffix) {
  display: flex;
  align-items: center;
}

.deepshadow .el-select .el-input__suffix {
  display: flex;
  align-items: center;
}

::v-deep(.el-select .el-input__suffix) {
  display: flex;
  align-items: center;
}

.stage-list {
  padding: 10px;
}
.stage-item {
  padding: 10px 0;
}
.stage-header {
  display: flex;
  align-items: center;
}
.circle-container {
  margin-right: 10px;
}
.outer-circle {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1px solid #dcdfe6;
  display: flex;
  align-items: center;
  justify-content: center;
}
.outer-circle.active {
  /* border-color: rgba(0, 186, 255, 0.8); */
  background-color: rgba(0, 186, 255, 0.2);
}
.inner-circle {
  width: 10px;
  height: 10px;
  background-color: #dcdfe6;
  border-radius: 50%;
}
.inner-circle.active {
  background-color: rgba(0, 186, 255, 0.8);
}
.el-row {
  margin-top: 10px;
  color: #4b4c4d;
}

.word-wrap {
  white-space: normal;
  word-wrap: break-word;
  word-break: break-word;
}

.image-wrapper {
  display: flex;
  flex-wrap: nowrap;
  overflow-x: auto;
  max-width: 200px;
  margin-top: 5px;
}

.image-container {
  position: relative;
  margin-right: 5px;
  flex-shrink: 0;
}

.progress-image {
  width: 60px;
  height: auto;
  border-radius: 4px;
  border: 1px solid #dcdfe6;
  cursor: pointer;
  transition: all 0.3s;
}

.progress-image:hover {
  border-color: #409eff;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}
</style>
